package com.paireach.bw.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.view.View;
import android.view.Window;

import com.paireach.bw.R;
import com.paireach.bw.adapter.QuestionsRecyAdapter;

/**
 * Created by ${cqc} on 2017/1/17.
 */

public class CommonQuestionActivity extends AppCompatActivity {


    private Toolbar toolbar;
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
            Transition bottom = TransitionInflater.from(this).inflateTransition(android.R.transition.slide_bottom);
            getWindow().setEnterTransition(bottom);
        }
        setContentView(R.layout.activity_common_question);
        findViews();
        initViews();
    }

    private void initViews() {
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                CommonQuestionActivity.this.finish();
                onBackPressed();
            }
        });

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        QuestionsRecyAdapter adapter = new QuestionsRecyAdapter(this);
        recyclerView.setAdapter(adapter);
        adapter.setmOnItemClickListener(new QuestionsRecyAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(CommonQuestionActivity.this);
                Intent intent = new Intent(CommonQuestionActivity.this, AnswerActivity.class);
                intent.putExtra("position", position);
                ActivityCompat.startActivity(CommonQuestionActivity.this, intent, options.toBundle());
            }
        });
    }

    private void findViews() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView_common_question_activity);
    }


}
